const fs = require("fs");
const path = require("path");
function fileUpload(file){
    let uploadName = path.basename(file.path);
    console.log('uploadName: ', uploadName);
    // 将本地文件放到服务器的static的文件目录中
    // 创建可读流
    const reader = fs.createReadStream(file.path);//实现读文件file.path是上传的图片所在的路径
    // 获取上传文件扩展名
    let filePath =  process.cwd() + `/static/upLoad/${uploadName}`;//获取上传的文件名(就是传到哪了)
    console.log('filePath: ', filePath);
    // 创建可写流
    const upStream = fs.createWriteStream(filePath);//写入文件
    // 可读流通过管道写入可写
    reader.pipe(upStream);
}
module.exports = fileUpload;